package com.fescoservice.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.fescoservice.model.SeekerEdu;
import com.fescoservice.model.SeekerEduId;

/**
 * A data access object (DAO) providing persistence and search support for
 * SeekerEdu entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.fescoservice.dao.SeekerEdu
 * @author MyEclipse Persistence Tools
 */

public class SeekerEduDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(SeekerEduDAO.class);
	// property constants
	public static final String START_YEAR = "startYear";
	public static final String START_MON = "startMon";
	public static final String END_YEAR = "endYear";
	public static final String END_MON = "endMon";
	public static final String EDU_SCHOOL = "eduSchool";
	public static final String EDU_LEVEL = "eduLevel";
	public static final String MAJOR_NAME = "majorName";
	public static final String MAJOR_DESC = "majorDesc";

	protected void initDao() {
		// do nothing
	}

	public void save(SeekerEdu transientInstance) {
		log.debug("saving SeekerEdu instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(SeekerEdu persistentInstance) {
		log.debug("deleting SeekerEdu instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public SeekerEdu findById(SeekerEduId id) {
		log.debug("getting SeekerEdu instance with id: " + id);
		try {
			SeekerEdu instance = (SeekerEdu) getHibernateTemplate().get(
					"com.fescoservice.model.SeekerEdu", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(SeekerEdu instance) {
		log.debug("finding SeekerEdu instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding SeekerEdu instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from SeekerEdu as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByStartYear(Object startYear) {
		return findByProperty(START_YEAR, startYear);
	}

	public List findByStartMon(Object startMon) {
		return findByProperty(START_MON, startMon);
	}

	public List findByEndYear(Object endYear) {
		return findByProperty(END_YEAR, endYear);
	}

	public List findByEndMon(Object endMon) {
		return findByProperty(END_MON, endMon);
	}

	public List findByEduSchool(Object eduSchool) {
		return findByProperty(EDU_SCHOOL, eduSchool);
	}

	public List findByEduLevel(Object eduLevel) {
		return findByProperty(EDU_LEVEL, eduLevel);
	}

	public List findByMajorName(Object majorName) {
		return findByProperty(MAJOR_NAME, majorName);
	}

	public List findByMajorDesc(Object majorDesc) {
		return findByProperty(MAJOR_DESC, majorDesc);
	}

	public List findAll() {
		log.debug("finding all SeekerEdu instances");
		try {
			String queryString = "from SeekerEdu";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public SeekerEdu merge(SeekerEdu detachedInstance) {
		log.debug("merging SeekerEdu instance");
		try {
			SeekerEdu result = (SeekerEdu) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(SeekerEdu instance) {
		log.debug("attaching dirty SeekerEdu instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(SeekerEdu instance) {
		log.debug("attaching clean SeekerEdu instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static SeekerEduDAO getFromApplicationContext(ApplicationContext ctx) {
		return (SeekerEduDAO) ctx.getBean("SeekerEduDAO");
	}
}